    //申请记录页面Url
    __str_apply_url = "https://i.51job.com/userset/my_apply.php";
  
    //已查看记录页面Url
    __str_view_url = "https://i.51job.com/userset/resume_browsed.php";
  
    //收藏记录页面Url
    __str_fav_url = "https://i.51job.com/userset/my_collection.php";

    //职位搜索页面Url
    __str_jobs_url = "https://we.51job.com/pc/search";

  //已申请记录列表
     __arr_apply_list = [];

    //每个页面加载的样式
    __css={
      'apply' :`
            /*申请页面样式调整start */

            .apox .gtbox{display: none !important;}
            .apox .e .l2{width: 160px!important;}

            .apox .e{
             height:50px !important;
             border: 0px !important;
             border-bottom:1px solid #eee  !important;
             height:50px;padding: 5px 20px!important ;
             margin-top: 0px !important;
             }

             .apox .e .li{line-height:20px !important;}

             .exrt .exmsg{position: relative;!important;}
            .dw_page{
                position: absolute !important;
                top: -65px !important;left: 600px !important;
                z-index: 99999 !important;
            }

            .dw_page .p_box{position:static !important;width: 600px !important;left: 0px !important;}

            .h_body .mt{height:auto !important;}


            /*申请页面样式调整end */
      `,
      'view' :`
          /*谁查看我页面样式调整start */
        .lmsg .e .txt{height: 30px !important;;padding: 0px !important;;}
        .lmsg .tit{margin: 0px !important ;padding: 0px 0 !important;}
        .lmsg .e .l1 p{ height:auto !important;}
        .c_666 {float: left !important;}
        .myCont .lmsg .e .l1{width: 550px !important;;} 
        .myCont .lmsg .e .l3{width: 380px !important;;}

        .lmsg .tit .txt{width: 100% !important;display: inline-block;margin-top: 0px !important;;}


          /*谁查看我页面样式调整end */
          `,
      'fav' :`

           #job_helper_box_select_all{margin-top:20px !important;}


            /*收藏页面样式调整start */
            .j_joblist .e {margin-bottom:2px!important; padding:5px !important;}
            .j_joblist .e .er .logo {display: none !important;}

            .j_joblist .e .info {
              height:20px !important;
              margin:0px !important;
            }

          .j_joblist .e .er {
              height: auto !important;
              margin-top:0px !important; 
          }
            
          .j_joblist .e .cname {
              margin-top: 0px!important;
              margin-bottom: 0px!important;
          }


          .j_page {
              position: absolute !important; 
              height: 32px !important;
              width: 600px !important;
              top: 5px !important;
              left: 300px !important;
          }



            /*收藏页面样式调整end */
          `,
      'jobs' :`
          /*职位列表页面样式调整start */
            #job_helper_box_select_all{margin-top:20px !important;}

            #job_helper_box button {padding: 5px !important;}

            /* 调整搜索页面左右栏目的宽度 start*/
              .j_result .rightbox {
                width: 200px !important
              }
              
              .j_result  .leftbox {
                width: 990px !important;
                margin-bottom: 30px !important;
              }
            
            /* 调整搜索页面左右栏目的宽度 end*/

            .popover-body{padding: 20px !important;} /*修正提示框宽度的问题*/

            .j_search {
              height:100px !important;
              padding-top: 10px !important;
              margin-bottom: 2px auto !important;
              margin-top: 2px auto !important;
            }

            .joblist-item-bot .br {width: 220px !important;;}
            .joblist-item-bot{margin-top:0px !important;}

            .j_search_in{background-color:#fff !important;}


            /* 职位列表右边 为您推荐样式调整 start*/
              .preference .e .jname {
                float: left !important;;
              }

              .preference .e {
                margin: 10px 10px 0 10px !important;;
                padding-bottom: 0px !important;;
              }

              .preference .e .cname {
                margin:5px 0 8px  !important;;
              }
              .preference .e .jname {
                font-size: 14px!important;;
              }
            /* 职位列表右边 为您推荐样式调整 end*/


            .joblist-item-bot .br .btn[data-v-70997ddd] {
                padding: 2px 10px 5px 10px !important;
                height: 25px !important;
                line-height: 25px !important;
            }

            .j_tlc .chall { margin-right: 5px  !important;;}
            .j_tlc .ss { margin-right: 8px !important;}

          /*职位列表页面样式调整end */
    `,
    }


get_apply_rst_list = async function (arrApplyList) {

  return new Promise((resolve, reject) => {

    let json_cvinfo = {};
    let json_items  = {};

    for (let i = 0; i < arrApplyList.length; i++) {
      json_items[arrApplyList[i].cvlogid]   = arrApplyList[i];
      json_cvinfo[arrApplyList[i].cvlogid]  = {
        "cvlogid": arrApplyList[i].cvlogid,
        "time": arrApplyList[i].timestamp,
        "pass": "1"
      };
    }

    var urlParams = jQuery.param({cvinfo:json_cvinfo});
    var url       = "https://i.51job.com/userset/ajax/apply.php?" + Math.random() + '&' + urlParams;

    fetch(url)
    .then(response => {
      if (!response.ok) {
        throw new Error(`HTTP error! status: ${response.status}`);
      }
      return response.arrayBuffer();
    })
    .then(buffer => {
      const decoder = new TextDecoder('gbk');
      var data = decoder.decode(buffer);

      //返回的不是json格式，去除掉两边的括号
      data = data.substring(1, data.length-1);

      //解析json格式
      data = JSON.parse(data);
      data = data.html;

      jQuery.each(data, function (id, value) {
        json_items[id].feedback = value;
        var apply_status = value.match(/<div class="d now">(.*?)<\/div>/)[1];
        json_items[id].apply_status = getStringBetweenTags(apply_status, '<label>', '</label>');
      });

      let arrRstList = [];
      for (let e in json_items) {
        arrRstList.push(json_items[e]);
      }

      resolve(arrRstList);
      return arrRstList;
    })
    .catch(error => {
      console.error('请求失败:', error);
      reject(arrApplyList);
      return arrApplyList;
    });

  });
}

parse_apply_info =  function(htmlContent){

    // 定义开始和结束标记
    const startTag  = '<div class="apox">';
    const endTag    = '<!--分页-->';
    let arrRstList  = [];
    main_info       = getStringBetweenTags(htmlContent,startTag,endTag);

    if( main_info == "" || main_info == null ){
     return [];
    };

    item_lists = main_info.split('<div class="e">');

    for (let i = 0; i < item_lists.length; i++) {

      item = item_lists[i];

      if( item.trim() !== "" ){

        job_link  = item.match(/https:\/\/jobs.51job.com\/all\/(\d+)\.html/)[0];
        job_id    = job_link.match(/\/all\/(\d+)\.html/)[1];

        var match = item.match(/<a class="zhn gt"[^>]*>(.*?)<\/a>/);
        if (match && match[1]) {
          job_name = match[1].trim();
        } else {
          job_name = "";
        }

        company_link  = item.match(/https:\/\/jobs.51job.com\/all\/co([a-zA-Z0-9\-_]+)\.html/)[0];
        company_id    = company_link.match(/\/all\/co([a-zA-Z0-9\-_]+)\.html/)[1];

        match = item.match(/<a class="gs"[^>]*>(.*?)<\/a>/);
        if (match && match[1]) {
          company_name = match[1].trim();
        } else {
          company_name ="";
        }
    
        apply_date      = getStringBetweenTags(item, '<label>申请于</label><span>', '</span>');
        apply_cv_name   = getStringBetweenTags(item, '<label>申请简历：</label><span', '">').trim().replace('title="', '');
        cvlogid         = item.match(/showdetail(\d+)/)[1];
        apply_resumeid  = item.match(/resumeid=(\d+)/)[1];
        timestamp       = getStringBetweenTags(item, 'sd'+cvlogid, '">').trim().replace('" value="', '');
        timestamp       = timestamp.match(/(\d+)/)[0];

        item_info       = {
                job_id: job_id,
                job_name: job_name,
                company_id: company_id,
                company_name: company_name,
                apply_date: apply_date,
                apply_status: null,
                cvlogid: cvlogid,
                timestamp:timestamp,
                apply_cv_name: apply_cv_name,
                apply_resumeid: apply_resumeid
        }

        arrRstList.push(item_info);
      }

      console.log(JSON.stringify(arrRstList));
    }

    //获取职位申请结果
   //return get_apply_rst_list(arrRstList);


    get_apply_rst_list(arrRstList)
    .then(result => {
      arrRstList =  result;
    })
    .catch(error => {
      return  arrRstList;
    });

    return arrRstList;

}

get_apply_info =  async function(page_num =1 ){

    return new Promise((resolve, reject) => {

      // 定义要请求的 URL
      const url = 'https://i.51job.com/userset/my_apply.php?lang=c&type=sh&tagType=all&page=' + page_num;

      showInfo('获取申请记录：第:'+page_num +"页","info");
      console.log('获取申请记录：第:'+page_num +"页");

       fetch(url)
      .then(response => {
        if (!response.ok) {
          throw new Error(`HTTP error! status: ${response.status}`);
        }
        return response.arrayBuffer();
      })
      .then(buffer => {

        const decoder = new TextDecoder('gbk');
        const data = decoder.decode(buffer);

        //共5页，到第</span><input id="jump_page" class="mytxt" type="text" value="1"/>

        var match = data.match(/共(.*?)页，到第/);
        if (match && match[1]) {
          total_page = parseInt(match[1].trim());
        } else {
          total_page = 0;
        }

        var arrRstList = [];
        //解析数据
        if( page_num > 0 ){
          arrRstList =  parse_apply_info(data);
        }

        //递归获取下一页数据
        if(page_num < total_page ){

          get_apply_info(page_num + 1)
          .then(result => {

            arrRstList =  arrRstList.concat(result);

            resolve(arrRstList);
          })
          .catch(error => {
            console.error(error);
            reject([]);
          });
        }else{
          showInfo("完成", "success");
          resolve(arrRstList);
        }

      })
      .catch(error => {
        reject([]);
        console.error('请求失败:', error);
      });

    });
}

parse_view_info=function(htmlContent){

  // 定义开始和结束标记
  const startTag = '<div class="lmsg">';
  const endTag = 'mqhope';
  arrRstList = [];

  main_info = getStringBetweenTags(htmlContent,startTag,endTag);

  if(main_info=="" || main_info==null){
    return [];
  };


  item_lists = main_info.split('<div class="e">');

  for (let i = 1; i < item_lists.length; i++) {
    item = item_lists[i];

      if(item.trim()!==""){

        //如果是自己申请的
        if(item.match(/我的申请/)){
            job_link  = item.match(/https:\/\/jobs.51job.com\/all\/(\d+)\.html/)[0];
            job_id    = job_link.match(/\/all\/(\d+)\.html/)[1];
            job_name  = getStringBetweenTags(item, job_link, '>').trim();
            job_name  = getStringBetweenTags(job_name, 'title="', '"').trim();
            view_type = "我的申请"
        }else{
            job_link  = null;
            job_id    = null;
            job_name  = null;
            view_type = "企业搜索"
        }


        company_link  = item.match(/https:\/\/jobs.51job.com\/all\/co([a-zA-Z0-9\-_]+)\.html/)[0];
        company_id    = company_link.match(/\/all\/co([a-zA-Z0-9\-_]+)\.html/)[1];
        company_name  = getStringBetweenTags(item, company_link+'"', '">').trim().replace('title="', '');

     
        last_view_date  = item.match(/\b\d{4}-\d{2}-\d{2}\b/g)[0];
        resume_id       = item.match(/resumeid=(\d+)/)[1];
        resume_name     = getStringBetweenTags(item, resume_id+'" class="cname"', '">').trim().replace('title="', '');

        fav_rank        = item.match(/width:([\d]+)px/)[1];
        feedback        = getStringBetweenTags(item, '<div class="h_body">', '</div>').trim();
        view_times      = item.match(/c_orange\">([\d\+]+)<\/strong>/)[1];

        item_info = {
          job_id: job_id,
          job_name: job_name,
          job_link: job_link,
          company_id: company_id,
          company_name: company_name,
          company_link: company_link,
          last_view_date: last_view_date,
          resume_id: resume_id,
          resume_name: resume_name,
          view_times: view_times,
          feedback: feedback,
          fav_rank: fav_rank,
          view_type: view_type
        }

        arrRstList.push(item_info);
      }

      console.log(JSON.stringify(arrRstList))
      //document.getElementById('job_helper_box_info').innerHTML = apply_txt + "<div><pre>"+JSON.stringify(apply_info)+"</pre></div>" ;
  }

  return arrRstList;
}

get_view_info= function(page_num =1 ){

  if(document.location.href.indexOf(__str_view_url) < 0){
    alert("需要在谁查看我页面获取");
     return [];
  }
 

    return new Promise((resolve, reject) => {

      // 定义要请求的 URL
      const url = 'https://i.51job.com/userset/resume_browsed.php?lang=c&type=2&page=' + page_num;

      showInfo('获取查看记录：第:'+page_num +"页","info");
      console.log('获取查看记录：第:'+page_num +"页");

       fetch(url)
      .then(response => {
        if (!response.ok) {
          throw new Error(`HTTP error! status: ${response.status}`);
        }
        return response.arrayBuffer();
      })
      .then(buffer => {
        const decoder = new TextDecoder('gbk');
        const data = decoder.decode(buffer);

        //共5页，到第</span><input id="jump_page" class="mytxt" type="text" value="1"/>

        var match = data.match(/共(.*?)页，到第/);
        if (match && match[1]) {
          total_page = parseInt(match[1].trim());
          current_page  = parseInt(getStringBetweenTags(data, '<input id="jump_page" class="mytxt" type="text" value="', '"'));
        } else {
          total_page = 0;
          current_page = 0;
        }

        let arrViewList = [];
        //解析数据
        if( page_num>0 ){
          arrViewList =  parse_view_info(data);
        }


        //递归获取下一页数据
        if(current_page < total_page ){

          get_view_info(current_page + 1)
          .then(result => {
            arrViewList =  arrViewList.concat(result)
            resolve(arrViewList);
          })
          .catch(error => {
            console.error(error);
            reject([]);
          });
        }else{
          showInfo("完成", "success");
          resolve(arrViewList);
        }


      })
      .catch(error => {
        console.error('请求失败:', error);
      });

    });
}


parse_fav_info=function(htmlContent){

  // 定义开始和结束标记
  const startTag = '<div class="j_joblist">';
  const endTag = 'j_tabs ftop';
  arrRstList = [];

  main_info = getStringBetweenTags(htmlContent,startTag,endTag);

  if(main_info=="" || main_info==null){
    return [];
  };


  item_lists = main_info.split('<div class="e"');

  for (let i = 1; i < item_lists.length; i++) {
    item = item_lists[i];

      if(item.trim()!==""){

        //collection_160018961
        job_id    = item.match(/collection_(\d+)/)[1];
        job_link  = "https://jobs.51job.com/all/" + job_id +".html";
        job_name  = getStringBetweenTags(item, '<span class="jname at">', '</span>').trim();

        company_link  = item.match(/https:\/\/jobs.51job.com\/all\/co([a-zA-Z0-9\-_]+)\.html/)[0];
        company_id    = company_link.match(/\/all\/co([a-zA-Z0-9\-_]+)\.html/)[1];
        company_name  = getStringBetweenTags(item, company_link+'" class="cname at">', '</a>').trim();

        item_info = {
          job_id: job_id,
          job_name: job_name,
          job_link: job_link,
          company_id: company_id,
          company_name: company_name,
          company_link: company_link
        }

        arrRstList.push(item_info);
      }

      console.log(JSON.stringify(arrRstList))
      //document.getElementById('job_helper_box_info').innerHTML = apply_txt + "<div><pre>"+JSON.stringify(apply_info)+"</pre></div>" ;
  }

  return arrRstList;
}

get_fav_info= function(page_num =1 ){

  if(document.location.href.indexOf(__str_fav_url) < 0){
    alert("需要在我的收藏页面获取");
     return [];
  }

    return new Promise((resolve, reject) => {

      // 定义要请求的 URL
      const url = 'https://i.51job.com/userset/my_collection.php?type=jobs&page=' + page_num;

      showInfo('获取收藏记录：第:'+page_num +"页","info");
      console.log('获取收藏记录：第:'+page_num +"页");

       fetch(url)
      .then(response => {
        if (!response.ok) {
          throw new Error(`HTTP error! status: ${response.status}`);
        }
        return response.arrayBuffer();
      })
      .then(buffer => {
        const decoder = new TextDecoder('gbk');
        const data = decoder.decode(buffer);
        //共5页，到第</span><input id="jump_page" class="mytxt" type="text" value="1"/>
        //共 2 页
        var match = data.match(/共 (.*?) 页/);
        if (match && match[1]) {
          total_page = parseInt(match[1].trim());
          current_page  = parseInt(getStringBetweenTags(data, '<input id="jump_page" class="mytxt" type="text" value="', '"'));
        } else {
          total_page = 0;
          current_page = 0;
        }

        let arrRstList = [];
        //解析数据
        if( page_num>0 ){
          arrRstList =  parse_fav_info(data);
        }

        //递归获取下一页数据
        if(current_page < total_page ){

          get_fav_info(current_page + 1)
          .then(result => {
            arrRstList =  arrRstList.concat(result)
            resolve(arrRstList);
          })
          .catch(error => {
            console.error(error);
            reject([]);
          });
        }else{
          showInfo("完成", "success");
          resolve(arrRstList);
        }


      })
      .catch(error => {
        console.error('请求失败:', error);
      });

    });
}

refresh_apply_info = async function(){

  if(document.location.href.indexOf(__str_apply_url) < 0){
    alert("需要在我的申请页面获取");
     return [];
  }
 
  get_apply_info(1)
  .then(result => {

    let json_items ={};
    let json_cvlogs = {}

    for (let i = 0; i < result.length; i++) {
      json_items[result[i].job_id] = result[i];
      json_cvlogs[result[i].cvlogid] = {
        "cvlogid": result[i].cvlogid,
        "time": result[i].timestamp,
        "pass": "1"
      }
    }

    chrome.storage.local.set({'51job_apply_list': json_items}, function() {
      console.log('51job_apply_list Save to chrome.storage.local.51job_apply_list');
    });

    jQuery("#job_helper_list_apply .monitor_num").html(result.length);

  })
  .catch(error => {
    console.error(error);
  });
}

refresh_view_info = async function(){
  
    get_view_info(1)
    .then(result => {

      let json_items ={};
      for (let i = 0; i < result.length; i++) {
        json_items[result[i].company_id] = result[i];
      }

      console.log(result)
      console.log(JSON.stringify(json_items));

      chrome.storage.local.set({'51job_view_list': json_items}, function() {
        console.log('51job_view_list Save to chrome.storage.local.51job_view_list');
      });

      jQuery("#job_helper_list_view .monitor_num").html(result.length);

    })
    .catch(error => {
      console.error(error);
    });
}

refresh_fav_info = async function(){
  
  get_fav_info(1)
  .then(result => {

    let json_items ={};
    for (let i = 0; i < result.length; i++) {
      json_items[result[i].job_id] = result[i];
    }

    console.log(result)
    console.log(JSON.stringify(json_items));

    chrome.storage.local.set({'51job_fav_list': json_items}, function() {
      console.log('51job_fav_list Save to chrome.storage.local.51job_fav_list');
    });

    jQuery("#job_helper_list_fav .monitor_num").html(result.length);

  })
  .catch(error => {
    console.error(error);
  });
}

//扩展收藏页面功能
fav_page_extend = function(result){

  if(document.location.href.indexOf(__str_fav_url) < 0 ){
    return;
  }

  //遍历申请列表，增加申请提示信息
  jQuery(".j_joblist .e").each(function(){

    let job_id = jQuery(this).attr("id").replace("collection_", "");

    if(__arr_apply_list[job_id]){

      var apply_date  = __arr_apply_list[job_id].apply_date;
      var apply_status = __arr_apply_list[job_id].apply_status;
      var feedback = __arr_apply_list[job_id].feedback;

      var strHtml = '<span class="job_helper_box_applyed">已申请(：' + apply_date + ':'+ apply_status +')</span>';
          strHtml += '<div class="job_helper_box_tips"><div class="job_helper_box_tips_content">'+ feedback  +'</div></div>';
          strHtml += '<div style="clear:both"></div>';
          jQuery(this).find(".jname ").after(strHtml);

          var popoverTrigger = jQuery(this).find(".job_helper_box_applyed").eq(0)[0];
          const popoverContent = jQuery(this).find(".job_helper_box_tips").eq(0)[0].innerHTML;

          console.log(popoverTrigger);
          console.log(popoverContent);

          // 初始化 Popover，将内容设置为隐藏元素的 HTML
          const popover = new bootstrap.Popover(popoverTrigger, {
              content: popoverContent,
              html: true,
              trigger: 'manual' // 设置为手动触发
          });

          jQuery(popoverTrigger).hover(
            function() {
                popover.show();
              },
            function() {
                popover.hide();
            }
          );

    }
  });

    //增加全选按钮

    var strHtml = `
    <label class="form-check-label" for="job_helper_box_select_all">
    <input type="checkbox" id="job_helper_box_select_all"    class="form-check-input"    value="1">
    全选</label>  `;
    //jQuery("#job_helper_action_btn").after(strHtml);

    jQuery(".mt_l .on").after(strHtml);

    jQuery("#job_helper_box_select_all").click(function(){

        var bChecked = jQuery(this).is(":checked");

        if(bChecked){
          jQuery(".j_joblist .e").addClass("on")
          jQuery(".j_joblist .checkbox").attr("checked","checked")
        }else{
          jQuery(".j_joblist .e").removeClass("on")
          jQuery(".j_joblist .checkbox").removeAttr("checked")
        }

        if($('input:checkbox[name="delivery_jobid"]:checked').length==0)
          {
              $("div.op span.but_sq,div.op span.but_sc,div.op span.but_sf").addClass("uck");
          }
          else
          {
              $("div.op span.but_sq,div.op span.but_sc,div.op span.but_sf").removeClass("uck");
          }
        //已选数量
        $('.num').text($("input[name='delivery_jobid']:checked").length)
        
        var jtabs = $('.j_tabs');
        if($("input[name='delivery_jobid']:checked").length>0){
          jtabs.show();
        } else {
          jtabs.hide();
        }

    })

}

//扩展职位搜索页面功能
jobs_page_extend = function(result){

  if(document.location.href.indexOf(__str_jobs_url) < 0 ){
    return;
  }

    //增加全选按钮
    var strHtml = `
    <input type="checkbox" id="job_helper_box_select_all"  class="form-check-input"  value="1">
    <label for="job_helper_box_select_all" class="form-check-label">全选</label>
    只显示近
    <input type="text" id="job_helper_box_pubdate_filter"  value="60">天
    `;

    jQuery(".chall").append(strHtml);

    jQuery("#job_helper_box_select_all").click(function(){
       var bChecked = jQuery(this).is(":checked");
       if(bChecked){
          jQuery(".joblist-item:not(.on)").find(".ick").trigger("click");
       }else{
          jQuery(".joblist-item").find(".ick").trigger("click");
       }
    })

}

//扩展谁查看我页面功能,翻页后刷新职位
view_page_extend_refresh_list = function(result){

  //遍历申请列表，增加申请提示信息
  jQuery(".pname").each(function(){

    var job_link  = jQuery(this).attr("href");
    var job_id    = job_link.match(/\/all\/(\d+)\.html/)[1];

    if(__arr_apply_list[job_id]){

      var apply_date  = __arr_apply_list[job_id].apply_date;
      var apply_status = __arr_apply_list[job_id].apply_status;
      var feedback = __arr_apply_list[job_id].feedback;

      var strHtml = '<span class="job_helper_box_applyed">(' + apply_date + '申请:'+ apply_status +')</span>';
          strHtml += '<div class="job_helper_box_tips"><div class="job_helper_box_tips_content">'+ feedback  +'</div></div>';
          strHtml += '<div style="clear:both"></div>';
          jQuery(this).after(strHtml);

          const popoverTrigger = jQuery(this).parent().find(".job_helper_box_applyed").eq(0)[0];
          const popoverContent = jQuery(this).parent().find(".job_helper_box_tips").eq(0)[0].innerHTML;

          // 初始化 Popover，将内容设置为隐藏元素的 HTML
          const popover = new bootstrap.Popover(popoverTrigger, {
              content: popoverContent,
              html: true,
              trigger: 'manual' // 设置为手动触发
          });

          jQuery(popoverTrigger).hover(
            function() {
                popover.show();
              },
            function() {
                popover.hide();
            }
          );

    }

  });

}

//扩展职位搜索页面功能,翻页后刷新职位
jobs_page_extend_refresh_list = function(result){

  let job_helper_box_pubdate_filter = parseInt(jQuery("#job_helper_box_pubdate_filter").val());
  let today =  timestamp_to_date(Date.now());

  //遍历申请列表，增加申请提示信息
  jQuery(".joblist-item-job-wrapper").each(function(){

    var subdiv =  jQuery(this).children().eq(0);
    let sensorsdata = JSON.parse(subdiv.attr("sensorsdata"));
    let job_id = sensorsdata.jobId;


    if(__arrJobList[job_id]){
      var job_info = __arrJobList[job_id];
      //confirmDateString
      jQuery(this).attr("title",job_info.jobDescribe);
      $(this).find(".joblist-item-bot .br .area").append(" "+ job_info.confirmDateString.substring(0,10));
  
      //按日期筛选
      if(dateDiff('d',job_info.confirmDateString.substring(0,10),today) > job_helper_box_pubdate_filter ){
        jQuery(this).parent().hide();
      }
    }

    if(__arr_apply_list[job_id]){

      var apply_date  = __arr_apply_list[job_id].apply_date;
      var apply_status = __arr_apply_list[job_id].apply_status;
      var feedback = __arr_apply_list[job_id].feedback;

      var strHtml = '<span class="job_helper_box_applyed">(' + apply_date + '申请:'+ apply_status +')</span>';
          strHtml += '<div class="job_helper_box_tips"><div class="job_helper_box_tips_content">'+ feedback  +'</div></div>';
          strHtml += '<div style="clear:both"></div>';
          jQuery(this).find(".jname ").after(strHtml);

          const popoverTrigger = jQuery(this).parent().find(".job_helper_box_applyed").eq(0)[0];
          const popoverContent = jQuery(this).parent().find(".job_helper_box_tips").eq(0)[0].innerHTML;

          // 初始化 Popover，将内容设置为隐藏元素的 HTML
          const popover = new bootstrap.Popover(popoverTrigger, {
              content: popoverContent,
              html: true,
              trigger: 'manual' // 设置为手动触发

          });

          jQuery(popoverTrigger).hover(
            function() {
                popover.show();
              },
            function() {
                popover.hide();
            }
          );

    }

  });


}


load_local_data = function(){

    // 异步获取数据
    chrome.storage.local.get(['51job_apply_list'], function(result) {

      result = result['51job_apply_list'];

      if(!result){result = {}}

      __arr_apply_list = result;

      jQuery("#job_helper_list_apply .monitor_num").html(Object.keys(result).length);


      if(document.location.href.indexOf(__str_jobs_url) >= 0 ){
        setTimeout(jobs_page_extend,2000);
      }

      if(document.location.href.indexOf(__str_apply_url) >= 0 ){
          //todo
      }

      if(document.location.href.indexOf(__str_view_url) >= 0 ){
          view_page_extend_refresh_list();
      }

      if(document.location.href.indexOf(__str_fav_url) >= 0 ){
        fav_page_extend();
      }

    });

    chrome.storage.local.get(['51job_view_list'], function(result) {
      result = result['51job_view_list'];
      __arr_view_list = result;

      if(!result){result = {}}
      jQuery("#job_helper_list_view .monitor_num").html(Object.keys(result).length);
    });

    chrome.storage.local.get(['51job_fav_list'], function(result) {
      result = result['51job_fav_list'];
      __arr_fav_list = result;

      if(!result){result = {}}
      jQuery("#job_helper_list_fav .monitor_num").html(Object.keys(result).length);
    });
}

//ajax调用后的hook
ajax_hook = function(e){

    let url = e.data.url;
    let response = e.data.response;
    
    if(url){

        //判断指定ajax请求,如果实现的是职位搜索列表，等页面渲染完成后，再附加扩展功能需要呈现的功能
        if(url.indexOf('https://we.51job.com/api/job/search-pc?api_key=51job') >= 0 ){
    
          var jsonRst = {}
          var result  = JSON.parse(response);
              result  = result.resultbody.job.items;
    
            for(var i=0; i< result.length; i++){
                jsonRst[result[i].jobId] = result[i];
            }
    
            __arrJobList = jsonRst;

            setTimeout(jobs_page_extend_refresh_list ,500);
    
        }
    }

}

